<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------

namespace app\video\home;
use app\common\controller\AuthCheck;
use think\facade\Log;
/**
 * 视频接口类
 * @package app\user\admin
 */
class VideoApi extends AuthCheck
{   
    /**
     * 获取视频上传地址和凭证
     * @author jason wang <120907037@qq.com>
     * @return mixed
     */
    public function get_create_upload_video_auth(){
        //参数接收
        $params = $this->getParams(1);//0 get 1 post 

        //数据验证
        $Validate = validate('VideoApi', 'validate');
        if( !$Validate -> scene('get_create_upload_video_auth') -> check($params) ){
            json_out(-1001, $Validate -> getError(), (object)[]);//验证失败
        }

        //赋值
        $user_id        = intval(isset($params["user_id"]) ? $params["user_id"] : 0);
        $title          = strval(isset($params["title"]) ? $params["title"] : '');
        $file_name      = strval(isset($params["file_name"]) ? $params["file_name"] : '');

        //数据返回   send_type=1   后端PHP使用上传方式
        if($params['send_type'] == 1){
            //逻辑处理
            $list = controller('VideoApilogic', 'logic') -> get_create_upload_video_auth_php($user_id, $title, $file_name);

            //跨域
            header('Access-Control-Allow-Origin: *');
            header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
            //后端上传
            return array_out($list['code'], $list['message'], (array)$list['data']);
        }else{
            //逻辑处理
            $list = controller('VideoApilogic', 'logic') -> get_create_upload_video_auth($user_id, $title, $file_name);

            //跨域
            header('Access-Control-Allow-Origin: *');
            header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
            json_out($list['code'], $list['message'], (object)$list['data']);
        }
    }

    /**
     * 获取视频上传地址和凭证
     * @author jason wang <120907037@qq.com>
     * @return mixed
     */
    public function get_create_upload_video(){
        //参数接收
        $params = $this->getParams(1);//0 get 1 post 
        
        //数据验证
        $Validate = validate('VideoApi', 'validate');
        if( !$Validate -> scene('get_create_upload_video') -> check($params) ){
            json_out(-1001, $Validate -> getError(), (object)[]);//验证失败
        } 

        //赋值
        $user_id        = intval(isset($params["user_id"]) ? $params["user_id"] : 0);
        $title          = strval(isset($params["title"]) ? $params["title"] : '');
        $file_name      = strval(isset($params["file_name"]) ? $params["file_name"] : '');
        $description    = strval(isset($params["description"]) ? $params["description"] : '');
        $cover_url      = strval(isset($params["cover_url"]) ? $params["cover_url"] : '');
        $tags           = strval(isset($params["tags"]) ? $params["tags"] : '');
        $play_type      = intval(isset($params["play_type"]) ? $params["play_type"] : 0);
        $is_immerse     = intval(isset($params["is_immerse"]) ? $params["is_immerse"] : 0);
        $is_rotate      = intval(isset($params["is_rotate"]) ? $params["is_rotate"] : 0);
        $is_original      = intval(isset($params["is_original"]) ? $params["is_original"] : 0);
        $file_size      = intval(isset($params["file_size"]) ? $params["file_size"] : 0);
        $video_classid  = intval(isset($params["video_classid"]) ? $params["video_classid"] : 0);
        $class_tage_array  = isset($params["class_tage_array"]) ? $params["class_tage_array"] : [];
        
        //逻辑处理
        $list = controller('VideoApilogic', 'logic') -> get_create_upload_video($user_id, $title, $file_name, $description, $cover_url, $tags, $play_type, $is_immerse, $is_rotate, $file_size, $video_classid, $class_tage_array, $is_original);

        //跨域
        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');

        //数据返回
        json_out($list['code'], $list['message'], (object)$list['data']);
    }

    /**
     * 提交视频信息
     * @author jason wang <120907037@qq.com>
     * @return mixed
     */
    public function submit_video_info(){
        //参数接收
        $params = $this->getParams(1);//0 get 1 post
        //数据验证
        $Validate = validate('VideoApi', 'validate');
        if( !$Validate -> scene('submit_video_info') -> check($params) ){
            json_out(-1001, $Validate -> getError(), (object)[]);//验证失败
        }

        //赋值
        $user_id        = intval(isset($params["user_id"]) ? $params["user_id"] : 0);
        $play_id        = intval(isset($params["play_id"]) ? $params["play_id"] : 0);
        $son_play_id    = intval(isset($params["son_play_id"]) ? $params["son_play_id"] : 0);
        $title          = strval(isset($params["title"]) ? $params["title"] : '');
        $description    = strval(isset($params["description"]) ? $params["description"] : '');
        $cover_url      = strval(isset($params["cover_url"]) ? $params["cover_url"] : '');
        $tags           = strval(isset($params["tags"]) ? $params["tags"] : '');
        $play_type      = intval(isset($params["play_type"]) ? $params["play_type"] : 0);
        $is_immerse     = intval(isset($params["is_immerse"]) ? $params["is_immerse"] : 0);
        $is_rotate      = intval(isset($params["is_rotate"]) ? $params["is_rotate"] : 0);
        $is_original      = intval(isset($params["is_original"]) ? $params["is_original"] : 0);
        $video_classid  = intval(isset($params["video_classid"]) ? $params["video_classid"] : 0);
        $class_tage_array  = isset($params["class_tage_array"]) ? $params["class_tage_array"] : [];
        $goods_id_array  = isset($params["goods_id_array"]) ? $params["goods_id_array"] : [];

        //跨域
        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');

        //逻辑处理
        $list = controller('VideoApilogic', 'logic') -> submit_video_info($user_id, $play_id, $son_play_id, $title, $description, $cover_url, $tags, $play_type, $is_immerse, $is_rotate, $video_classid, $class_tage_array, $is_original, $goods_id_array);

        //数据返回
        if($params['send_type'] == 1){
            //后端上传
            return array_out($list['code'], $list['message'], (array)$list['data']);
        }else{
            json_out($list['code'], $list['message'], (object)$list['data']);
        }
    }

    /**
     * 刷新视频上传凭证
     * @author jason wang <120907037@qq.com>
     * @return mixed
     */
    public function get_refresh_upload_video_request(){
        //参数接收
        $params = $this->getParams(0);//0 get 1 post 
        
        //数据验证
        $Validate = validate('VideoApi', 'validate');
        if( !$Validate -> scene('get_refresh_upload_video_request') -> check($params) ){
            json_out(-1001, $Validate -> getError(), (object)[]);//验证失败
        }

        //赋值
        $user_id        = intval(isset($params["user_id"]) ? $params["user_id"] : 0);
        $video_id          = strval(isset($params["video_id"]) ? $params["video_id"] : '');

        //逻辑处理
        $list = controller('VideoApilogic', 'logic') -> get_refresh_upload_video_request($user_id, $video_id);

        //跨域
        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');

        //数据返回
        json_out($list['code'], $list['message'], (object)$list['data']);        
    }

    
    
    /**
     * 获取视频播放凭证
     * @author jason wang <120907037@qq.com>
     * @return mixed
     */
    public function get_video_play_auth(){
        //参数接收
        $params = $this->getParams(0);//0 get 1 post 
        
        //数据验证
        $Validate = validate('VideoApi', 'validate');
        if( !$Validate -> scene('get_video_play_auth') -> check($params) ){
            json_out(-1001, $Validate -> getError(), (object)[]);//验证失败
        }

        //赋值
        $user_id        = intval(isset($params["user_id"]) ? $params["user_id"] : 0);
        $play_id        = intval(isset($params["play_id"]) ? $params["play_id"] : 0);


        //逻辑处理
        $list = controller('VideoApilogic', 'logic') -> get_video_play_auth($user_id, $play_id);

        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');

        //数据返回
        json_out($list['code'], $list['message'], (object)$list['data']);
        
    }




}
